$(function(){
    //新商品渲染
    $.ajax({
        type: "GET",
        url: "http://localhost:8888/public/new_goods.json",
        dataType: "json",
        success: function (data) {
            render( data )
            //懒加载
            $('.lazy').lazyload()
        }
    });

    let frag_commodities_wrap1 = $('#frag-commodities-wrap1');

    function render(res) {
        frag_commodities_wrap1.append(res.new_goods.map(item => 
            `<div class="frag-commodities-list-item">
            <a href='${item.link}'>
                <div class="frag-commodities-item-image">
                    <img class='lazy' data-original="${item.img}" alt="">
                </div>
                <div class="frag-commodities-item-name">${item.goods_name}</div>
                <div class="frag-commodities-item-info">
                    <div class="frag-commodities-item-price">
                        <span class="DisplayPrice">￥
                            <span class="display-price-value highlight">
                                <span>${item.new_price}</span>
                            </span>
                            <span class="display-price-original">
                                <span>${item.old_price}</span>
                            </span>
                        </span>
                    </div>
                    <div class="frag-commodities-item-sales"> ${item.sales_num} </div>
                </div>
                </a>
            </div>`
        ).join(""))
    }
})
